// export function subscribeMessage() {
//   // 调用订阅
//   console.log('调用订阅')
//   uni.requestSubscribeMessage({
//     tmplIds: ['7bWWuxVF5sQIoS0zzS8a01e_HVeWh5mhxBirGtWHhkc','G0tFZxCpLIjbiffMYt5XQZzGXBlYEruPVsw-Zg_5_gM', 'Mr-GyqusCXzQxx9rEj_E_hWvVKbvngKUbSiD2lAE6eM'],
//     success(res) { 
//       console.log(res)
//     },
//     fail(error){
//       console.log(error)
//     }
//   })
// }
export function subscribeMessage() {
  // 调用订阅
  console.log('调用订阅')
  const pushReservationTmplIds = '7bWWuxVF5sQIoS0zzS8a01e_HVeWh5mhxBirGtWHhkc';
  uni.requestSubscribeMessage({
    tmplIds: ['7bWWuxVF5sQIoS0zzS8a01e_HVeWh5mhxBirGtWHhkc','G0tFZxCpLIjbiffMYt5XQZzGXBlYEruPVsw-Zg_5_gM', 'Mr-GyqusCXzQxx9rEj_E_hWvVKbvngKUbSiD2lAE6eM'],
    success(res) { 
		if (res[pushReservationTmplIds] === 'accept') {
		  console.log('已授权')
		} else if (res[pushReservationTmplIds] === 'reject') {
		  // 用户历史操作有设置了拒绝 or 关闭了订阅消息的主（总）开关，导致无法推送
		  // console.log(res, '0 拒绝 or 关闭了订阅消息的主（总）开关---');
		  guideOpenSubscribeMessage();
		} else {
		  uni.showToast({
			title: '授权订阅消息有误',
			icon: 'none'
		  });
		}
    },
    fail(res){
		// 20004:用户关闭了主开关，无法进行订阅,引导开启
		if (res.errCode == 20004) {
		  // console.log(res, 'fail:用户关闭了主开关，无法进行订阅,引导开启---');
		  guideOpenSubscribeMessage();
		}
    }
  })
}
// 无调用
export function subscribeMessageOne() {
  // 调用订阅
  console.log('调用订阅')
  const pushReservationTmplIds = '13HIkv48l_fZnrjkmYVKlcxczq8vHiiaXqoOWfTtuSQ';
  uni.requestSubscribeMessage({
    tmplIds: ['13HIkv48l_fZnrjkmYVKlcxczq8vHiiaXqoOWfTtuSQ'],
    success(res) { 
		if (res[pushReservationTmplIds] === 'accept') {
		  console.log('已授权')
		} else if (res[pushReservationTmplIds] === 'reject') {
		  // 用户历史操作有设置了拒绝 or 关闭了订阅消息的主（总）开关，导致无法推送
		  // console.log(res, '0 拒绝 or 关闭了订阅消息的主（总）开关---');
		  guideOpenSubscribeMessage();
		} else {
		  uni.showToast({
			title: '授权订阅消息有误',
			icon: 'none'
		  });
		}
    },
    fail(res){
		// 20004:用户关闭了主开关，无法进行订阅,引导开启
		if (res.errCode == 20004) {
		  // console.log(res, 'fail:用户关闭了主开关，无法进行订阅,引导开启---');
		  guideOpenSubscribeMessage();
		}
    }
  })
}
// 无调用
export function subscribeMessageTwo() {
  // 调用订阅
  console.log('调用订阅')
  const pushReservationTmplIds = '8fDSVCHLy-v0uBdJvA-DiJHH6lMkmIL6Bli_whuogZ4';
  uni.requestSubscribeMessage({
    tmplIds: ['8fDSVCHLy-v0uBdJvA-DiJHH6lMkmIL6Bli_whuogZ4'],
    success(res) { 
		if (res[pushReservationTmplIds] === 'accept') {
		  console.log('已授权')
		} else if (res[pushReservationTmplIds] === 'reject') {
		  // 用户历史操作有设置了拒绝 or 关闭了订阅消息的主（总）开关，导致无法推送
		  // console.log(res, '0 拒绝 or 关闭了订阅消息的主（总）开关---');
		  guideOpenSubscribeMessage();
		} else {
		  uni.showToast({
			title: '授权订阅消息有误',
			icon: 'none'
		  });
		}
    },
    fail(res){
		// 20004:用户关闭了主开关，无法进行订阅,引导开启
		if (res.errCode == 20004) {
		  // console.log(res, 'fail:用户关闭了主开关，无法进行订阅,引导开启---');
		  guideOpenSubscribeMessage();
		}
    }
  })
}
function guideOpenSubscribeMessage() {
    //引导用户，手动引导用户去设置页开启，
	uni.showModal({
	  title: "请求授权订阅消息",
	  content: "检测到您没有开启订阅消息的权限，是否去设置？",
	  success: function (res) {
		if (res.cancel) {
		  uni.showToast({ title: "拒绝授权", icon: "none" });
		} else if (res.confirm) {
		  uni.openSetting({
			success: function (dataAu) {
			  console.log("openSetting",dataAu);
			  if (dataAu.authSetting["scope.userLocation"] == true) {
				uni.showToast({ title: "授权成功", icon: "none" });
				//再次授权，调用wx.getLocation的API
			  } else {
				uni.showToast({ title: "授权失败", icon: "none" });
			  }
			},
		  });
		}
	  },
	});
  }